from wtforms import Form, StringField, validators, ValidationError


class MenuEdit(Form):
    id = StringField(validators=[validators.DataRequired(message='id为空')])
    parent_id = StringField(validators=[validators.NumberRange(min=0, max=None, message='父id为空')])

    def validate_parent_id(self, field):
        print(self.id.data)
        print(field.data)
        if (field.data != 0) and (self.id.data == field.data):
            raise ValidationError('父菜单不能为当前菜单')
